X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/8534e46e400268c5ceffb3b14f02cef39eedae8f..3de51c6f55d304f038df1b77c8ab346e2a187fe1:/Super%20Polarity/LetterChooseWidget.cs diff --git a/Super Polarity/LetterChooseWidget.cs b/Super Polarity/LetterChooseWidget.cs new file mode 100644 index 0000000..e52733f --- /dev/null +++ b/Super Polarity/LetterChooseWidget.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class LetterChooseWidget : Widget + { + int CurrentChar; + bool Locked; + int LockRate; + int CurrentTime; + + SpriteFont Font; + + public LetterChooseWidget(SuperPolarity game, Vector2 position) : base(game, position) + { + Active = false; + CurrentChar = 65; + Font = game.Content.Load("Fonts\\bigfont"); + LockRate = 300; + CurrentTime = 0; + + InputController.Bind("moveY", HandleMovement); + } + + public void HandleMovement(float value) + { + if (!Active) { return; } + + if (value > 0.8 && !Locked) { + CurrentChar = CurrentChar + 1; + + if (CurrentChar > 90) + { + CurrentChar = 32; + } + + Locked = true; + } + + if (value < -0.8 && !Locked) { + CurrentChar = CurrentChar - 1; + + if (CurrentChar < 32) + { + CurrentChar = 90; + } + + Locked = true; + } + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + if (CurrentTime > LockRate) + { + CurrentTime = 0; + Locked = false; + } + } + + public string Value() + { + return char.ConvertFromUtf32(CurrentChar); + } + + public override void Draw(SpriteBatch spriteBatch) + { + var color = new Color(0, 0, 0, 128); + if (Active) + { + color = new Color(201, 0, 68, 255); + } + spriteBatch.DrawString(Font, Value(), Position, color); + } + } +}